import util from '../../common/js/util'
import NProgress from 'nprogress'
import axios from 'axios'
import address from "../../../models/dict/address.js"  //任务字典模块
import moment from 'moment'

import task from "../../../models/dict/task.js"  //任务字典模块
import array from "../../../models/comm/array.js"  //数组操作模块
import yz from "../../../models/comm/yz.js"  //数组操作模块
import Vue from 'vue'
import tRoot from './info/tRoot.vue'
import tDefault from './info/tDefault.vue'
import t100 from './info/t100.vue'
import t200 from './info/t200.vue'
import t300 from './info/t300.vue'
import t400 from './info/t400.vue'
import t500 from './info/t500.vue'
import t600 from './info/t600.vue'
import t700 from './info/t700.vue'
import t800 from './info/t800.vue'
import t900 from './info/t900.vue'
import chType from '../../../models/dict/clothesSizeType'
import customerOrderShow from '../Order/customerOrderShow';



export default {




    data() {
        return {



            page: 1,
            filters: {},

            listLoading: false,
            total: 1,
            currObj: task.fmtTask(),

            customerOrder: {

            },
            node: {

            },
            nodeList: {

            },
            loadCustomerOrder: false,
            ld: {},

            loading: true




        }
    },
    methods: {

        getTask() {
            this.loading = true
            if (this.taskId && this.taskId != "") {
                axios.post("/a", {
                    class: "task",
                    para: "getTask",
                    j: {
                        _id: this.taskId
                    }

                }).then((res) => {
                    if (res.data.re == "ok") {
                        this.currObj = task.fmtTask(res.data.info)

                        this.getCustomerOrder();

                    } else {
                        alert(JSON.stringify(res.data));
                    }
                });
            }

        },

        closeTaskDialog() {
            this.o.showTaskDialog = false;

        },
        wOpen() {

            console.log("打开了我的任务窗口,正在加载数据");

            this.getTask();
        },
        getCustomerOrder() {

            if (this.currObj.customerOrderId) {
                axios.post("/a", {
                    class: "customerOrder",
                    para: "getCustomerOrder",
                    j: {
                        _id: this.currObj.customerOrderId
                    }

                }).then((res) => {
                    if (res.data.re == "ok") {
                        this.customerOrder = res.data.info



                        this.nodeList = this.customerOrder.flow[this.currObj.flowClassId].nodeList

                        this.nodeList.forEach(function (element) {

                            if (this.currObj.nodeId == element.id) {

                                this.node = element
                            }

                        }, this);

                        this.currObj.detail = task.fmtSizeDetail(this.currObj, this.customerOrder);
                        this.loading = false

                    } else {
                        alert(JSON.stringify(res.data));
                    }
                });
            }
            else {
                this.loading = false
            }



        },
        getClothesClassName(classId) {

            return chType.getClassName(classId)
        },
        getTaskClassName(classId) {
            return task.getClassName(classId)
        },
        getTaskStatusName(statusId) {
            return yz.IsNullThen(task.getStatus(statusId), {}).name

        },
        saveMyTask() {
            var j = {
                detail: this.currObj.detail,
                _id: this.currObj._id
            };

            if (this.currObj.taskClassId == "200") {
                //工价有两组detail, detail是合计费用 detail2是单件费用
                j.detail2 = this.currObj.detail2
            }

            if (this.currObj.taskClassId == "300") {
                //如果是制版, 允许填入基础码
                j.defaultSizeId = this.currObj.defaultSizeId
            }

            axios.post("/a", {
                class: "task",
                para: "saveMyTask",
                j: j
            }).then((res) => {
                if (res.data.re == "ok") {

                    this.o.showTaskDialog = false;



                } else {
                    alert(JSON.stringify(res.data));
                }
            });

        },
        doneTask() {




        },


        allDone() {

            switch (this.currObj.taskClassId) {
                case "500":
                    this.currObj.detail.forEach(function (item) {
                        item.sectionDoneNum = item.num
                    }, this);
                    break;
                case "600":
                    this.currObj.detail.forEach(function (item) {
                        item.sewDoneNum = item.sectionDoneNum
                    }, this);
                    break;
                case "700":
                    this.currObj.detail.forEach(function (item) {
                        item.completeDoneNum = item.sewDoneNum
                    }, this);
                    break;
                case "800":
                    this.currObj.detail.forEach(function (item) {
                        item.cdeliverDoneNum = item.clothesDoneNum
                    }, this);
                    break;
                default:
                    break;
            }

            this.$message('操作完毕,等待提交 ');


        },
        getTitle() {
            return "任务详情, 最后更新:" + moment(this.currObj.changeTime).format("YYYY-MM-DD HH:mm:ss")
        }


    },
    props: ['taskId', 'showTaskDialog', "o"],


    mounted() {



    }
    ,
    components: {

        t100,
        t200,
        t300,
        t400,
        t500,
        t600,
        t700,
        t800,
        t900,
        customerOrderShow,
        tRoot,
        tDefault


    }
}
